package com.glela.controller;

import com.alibaba.fastjson.JSONObject;
import com.glela.api.pay.yeepay.component.YeePay;
import com.glela.api.pay.yeepay.component.impl.YeePayImpl;
import com.glela.api.pay.yeepay.model.YeePayAliModel;
import com.glela.api.pay.yeepay.model.YeePayDivideModel;
import com.glela.api.pay.yeepay.model.YeePayNetSilverModel;
import com.glela.api.pay.yeepay.model.YeePayRefundModel;
import com.glela.api.pay.yeepay.model.YeePayWeChatModel;
import com.glela.common.util.YeePayAESUtil;

public class Test {

	public static void main(String[] args) {

		// 微信Demo
		// getWechat();
		
		// 支付宝Demo
		 getAliPay();
		
		// 快捷支付Demo
		// getNetSilverString();

		// 解析结果
		// parseResult();
	}

	/**
	 * 支付宝Demo
	 */
	public static void getAliPay() {

		YeePayAliModel aliModel = new YeePayAliModel();
		
		// 支付宝额外提供IP地址
		aliModel.setIp("101.228.219.92");

		// 基础参数
		aliModel.setRequestid("RetryAli148187593179406301"); // 订单号
		aliModel.setAmount("0.01"); // 支付金额（元）
		aliModel.setAssure("0"); // 是否担保 0否 1是
		aliModel.setProductname("测试商品"); // 商品名称 可选
		// yeePaySilver.setProductcat("Test"); // 商品类别 可选
		aliModel.setProductdesc("校妆网商品"); // 商品描述
		aliModel.setDivideinfo(""); // 分账信息
		aliModel.setCallbackurl("http://dev.glela.com/yg-c-platform.deploy.url/order/yeePayNetServerNotify"); // 点对点回调地址
		aliModel.setWebcallbackurl(""); // 页面通知地址 为空则默认转跳到后台地址
		// yeePaySilver.setBankid("CCB-NET-B2C"); // 易宝银行ID 可选
		aliModel.setPeriod(""); // 单位 ：天；当assure=1 时必填， 最大值：30 担保有效期
		// yeePaySilver.setMemo("V1.0"); // 商户备注 可选
		aliModel.setOrderexpdate("20"); // 订单支付有效时间

		YeePay yeePay = new YeePayImpl();
		String result = yeePay.yeePayTradeAlipay(aliModel);
		System.out.println(result);

	}

	public static void getWechat() {

		YeePayWeChatModel weChatModel = new YeePayWeChatModel();

		weChatModel.setIp("101.228.219.92");

		// 基础参数
		weChatModel.setPayproducttype("WECHATAPP");
		weChatModel.setRequestid("QWE148187593179406301"); // 订单号
		weChatModel.setAmount("0.01"); // 支付金额（元）
		weChatModel.setAssure("0"); // 是否担保 0否 1是
		weChatModel.setProductname("测试商品"); // 商品名称 可选
		// yeePaySilver.setProductcat("Test"); // 商品类别 可选
		weChatModel.setProductdesc("微信测试商品"); // 商品描述
		weChatModel.setDivideinfo(""); // 分账信息
		weChatModel.setCallbackurl("http://dev.glela.com/yg-c-platform.deploy.url/order/yeePayNetServerNotify"); // 点对点回调地址
		weChatModel.setWebcallbackurl(""); // 页面通知地址 为空则默认转跳到后台地址
		// yeePaySilver.setBankid("CCB-NET-B2C"); // 易宝银行ID 可选
		weChatModel.setPeriod(""); // 单位 ：天；当assure=1 时必填， 最大值：30 担保有效期
		// yeePaySilver.setMemo("V1.0"); // 商户备注 可选
		weChatModel.setOrderexpdate("20"); // 订单支付有效时间
		weChatModel.setUserno("152");

		YeePay yeePay = new YeePayImpl();
		String result = yeePay.yeePayTradeWeChat(weChatModel);
		System.out.println(result);
	}

	/**
	 * 分账请求示例 罗列出来的参数都是必填的
	 */
	public static void getDivideString() {

		YeePayDivideModel model = new YeePayDivideModel();
		model.setRequestid(""); // 标识分账唯一的接口
		model.setOrderrequestid(""); // 支付成功的订单号
		model.setDivideinfo(""); // 分账详细信息

		YeePay yeePay = new YeePayImpl();
		String result = yeePay.yeePayDivide(model);

		System.out.println(result);
	}

	/**
	 * 退款示例
	 */
	public static void getRefundString() {

		YeePayRefundModel model = new YeePayRefundModel();
		model.setOrderrequestid("P148128551666118009"); // 请求退款的单号
		model.setRequestid("A148067308108280005"); // 售后单号
		model.setAmount("0.01");
		model.setConfirm("1"); // 确认退款 固定值1
		model.setDivideinfo(""); // 不填写则默认从主账户上扣款
		model.setMemo("测试退款"); // 商户备注

		YeePay yeePay = new YeePayImpl();
		String result = yeePay.yeePayRefund(model);

		System.out.println(result);

	}

	/**
	 * 快捷支付示例
	 */
	public static void getNetSilverString() {
		YeePayNetSilverModel yeePaySilver = new YeePayNetSilverModel();
		// 网银参数
		yeePaySilver.setPayproducttype("ONEKEY");// 固定值SALES 一键支付ONEKEY
		yeePaySilver.setUserno("152"); // 商户的用户识别 userID 252 152
		/*
		 * yeePaySilver.setCardname("毛泽尧"); // 持卡人姓名 可选
		 * yeePaySilver.setIdcard("421022199301040611"); // 身份证号 可选
		 * yeePaySilver.setBankcardnum("6217001210080190554"); // 银行卡卡号 可选
		 * yeePaySilver.setMobilephone("18827070700"); // 银行预留手机号码 可选
		 */

		// 基础参数
		// yeePaySilver.setRequestid("YTQQ148128868047717513"); // 订单号
		yeePaySilver.setRequestid("ONEKEY148128868047717513"); // 订单号
		yeePaySilver.setAmount("0.01"); // 支付金额（元）
		yeePaySilver.setAssure("0"); // 是否担保 0否 1是
		yeePaySilver.setProductname("校妆网商品"); // 商品名称 必填
		// yeePaySilver.setProductcat("Test"); // 商品类别 可选
		yeePaySilver.setProductdesc("校妆网商品"); // 商品描述
		yeePaySilver.setDivideinfo(""); // 分账信息
		yeePaySilver.setCallbackurl("http://dev.api.glela.com/yg_platform/order/yeePayNetServerNotify"); // 点对点回调地址
		yeePaySilver.setWebcallbackurl(""); // 页面通知地址 为空则默认转跳到后台地址
		// yeePaySilver.setBankid("CCB-NET-B2C"); // 易宝银行ID 可选
		yeePaySilver.setPeriod(""); // 单位 ：天；当assure=1 时必填， 最大值：30 担保有效期
		// yeePaySilver.setMemo("V1.0"); // 商户备注 可选
		yeePaySilver.setOrderexpdate("20"); // 订单支付有效时间

		YeePay yeePay = new YeePayImpl();
		String result = yeePay.yeePayTradeNetSilver(yeePaySilver);

		System.out.println(result);
	}

	/**
	 * 解析快捷支付参数
	 */
	public static void parsing() {
		String data = "{\"data\":\"7AA9796A34B6311E85B5177762893055E737CDC7477606D752ACC75CEF62724C0E53C2910842C0222F25A0BF523A7A29CFE24D500347BBE8C5E868FF748F38A100B4165430F506C0DBAE2C265DA85DAEBFA8FD05403A1606129D5B031E3709D2C9BCFDE80DB78B79197EC82CA059EED4BCB342F411DF3CAD2AD2ACB4147353A1A35245113F5C9DF49C14ADE3A507A4724323A4F816E4540A32DD11AB19CB64D891D1494D122394A68BC4732668EB0032B7EBA0B3B7CC21CFFA0858C913172F73D7872CD25DF12B4562A89F130E778852541E914D3685976DE4640988CF35955BA4187BC8BFBE49B6A17741AE6B49B30E749C28EF4B9B52B99F065BED84EF96D48DEAA3B6ECFF3082A6BF5F6A0149A90AAC8FDD3443B798FAF05A2AFD45DA1D90E7FFD076EF37119924FDF02B29EC1E3A409A795BB3AFCB7E3DAF3B0D908611AF5307598D1D8C6C52961523FF00B57A73BFC9F3E594F8816D114053790ADCE971D07280FAEA588E8FC334690852B57F8338FB86DACA176C33271B05FC61DD07EE582F9F224FF54493D213ED75F22424C60D478E66FC8762D6DD3A4CF620EBDE4B64F2F2975670E30299A8AA8760DB21F6E191D6BBD29393000A850E7CC0969F507003C3123EC5C39031F601D3F2BDE4ECDC7421B9F7A5C8043BCA7C48241B3B8F42B7F662F4FFCC76C5038F2F313374921696E1D0DABB8045836ACF20B94D172505B65B73122BEB5CD1FAB1F08E053EAB732767C2D69AFB00DEDB7F57262D47C489316BCB2D20F69690FD19ABF65BE0F2AE0176FE3537CBB18AFC3ED0409CEBD4614C9F1AF77BFBCC23C4B335BB863FE8367FA590D2CD922F1E66134268AECF4311880F5B41EC90BB1AF061A4FB5145A196E7F995E1C7A4FAB84A9ABAA924AE133B826BC48C62648E5443B2A050A06EABF390857B042271BEBC86D9C211068CFCC3239D04F46FA7CC3FD90D2A9E1363F6551C1AB75197F43C734F131CEDFED4D8AB263C4040F0355A3AAB27587F36624876F12BB09842F46359586BAC4F19101112116CAFFFDE61E5B3F445E2AB355DB50FB47FF4B1B13E7B53E41C89D0C85B3AD36F3373D5079BB2F39BB6535F72E3B5E241F4F0B6EB260D152D6A3AD4406A06EC21C5A43BE0F3D1E130228D73B00C70D34C60E0C9DB6456394C8674802E677A0A6378F587D49D81F44FEA13F88C0F2EAE108D17E814AE867D124C8705751A6C52D51CF2A97037819A8284E74DBFC4586C6F51DDCF33320973764C77F247B5B0A43A1F56891CC5A259CC9900975530B71B77200CCB39D64EF64E064AA4F733FDC33F8BCC36E4C521377B64B6778F8930EFE7C64CC64B6F70F9F610ADC9DE9B0494691279DFBE34FE075F6F014D095511E514ADF31381FA36641771BE05BD42E2477034CE1D525C46CA8BD0608112AC17804279B74299562C1373619A2646699038B2FFFC9D9C8D14D5953010BA53EC7B\"}";

		String wait = JSONObject.parseObject(data).get("data").toString();

		String result = YeePayAESUtil.decrypt(wait, YeePay.SECRET_KEY.substring(0, 16));

		System.out.println(result);

	}

	/**
	 * 解析支付成功的参数
	 */
	public static void parseResult() {
		String data = "AA95FB8479B3AD200DBE42A2F1DFB905B169B67A7EAFA5D3C60449095DF5B43DDB505A78F776A779D1BA78989ECE79079BB8E70204A3358FAEE46219497C2905DBA0AE309DDC6A8ED2BFB9EC98610FE566CBA83B406BDCB1A8152C05A697CFF880CDDA183516E30567B1805FAEF6B9EFF2C2AE1E53D1D586A28ECC389383E4830DD90D4D8AF91FE6C239853A03AD075CCDECA87F9F8F7B1CDB39E2DBD156B2E252311E3CF6AFD7EE6219D75D43C5A3EC";
		String result = YeePayAESUtil.decrypt(data,
				"lF0386j067MWZb7817003M8o32iW7918H9Fk3JRV758P10lp182T7B8zte2u".substring(0, 16));
		System.out.println(result);

		/*
		 * JSONObject requestJson = JSONObject.parseObject(result); String
		 * customernumber = requestJson.getString("customernumber"); String
		 * requestid = requestJson.getString("requestid"); String code =
		 * requestJson.getString("code"); String notifytype =
		 * requestJson.getString("notifytype"); String externalid =
		 * requestJson.getString("externalid"); String amount =
		 * requestJson.getString("amount"); String cardno =
		 * requestJson.getString("cardno"); String bankcode =
		 * requestJson.getString("bankcode"); String cardtype =
		 * requestJson.getString("cardtype"); String paydate =
		 * requestJson.getString("paydate"); String payProduct =
		 * requestJson.getString("payProduct");
		 */
		// String hmac = requestJson.getString("hmac");

	}

	// {"data":"7AA9796A34B6311E85B5177762893055E737CDC7477606D752ACC75CEF62724C0E53C2910842C0222F25A0BF523A7A29CFE24D500347BBE8C5E868FF748F38A100B4165430F506C0DBAE2C265DA85DAEBFA8FD05403A1606129D5B031E3709D2C9BCFDE80DB78B79197EC82CA059EED4BCB342F411DF3CAD2AD2ACB4147353A1A35245113F5C9DF49C14ADE3A507A4724323A4F816E4540A32DD11AB19CB64D891D1494D122394A68BC4732668EB0032B7EBA0B3B7CC21CFFA0858C913172F73D7872CD25DF12B4562A89F130E778852541E914D3685976DE4640988CF35955BA4187BC8BFBE49B6A17741AE6B49B30E749C28EF4B9B52B99F065BED84EF96D48DEAA3B6ECFF3082A6BF5F6A0149A90AAC8FDD3443B798FAF05A2AFD45DA1D90E7FFD076EF37119924FDF02B29EC1E3A409A795BB3AFCB7E3DAF3B0D908611AF5307598D1D8C6C52961523FF00B57A73BFC9F3E594F8816D114053790ADCE971D07280FAEA588E8FC334690852B57F8338FB86DACA176C33271B05FC61DD07EE582F9F224FF54493D213ED75F22424C60D478E66FC8762D6DD3A4CF620EBDE4B64F2F2975670E30299A8AA8760DB21F6E191D6BBD29393000A850E7CC0969F507003C3123EC5C39031F601D3F2BDE4ECDC7421B9F7A5C8043BCA7C48241B3B8F42B7F662F4FFCC76C5038F2F313374921696E1D0DABB8045836ACF20B94D172505B65B73122BEB5CD1FAB1F08E053EAB732767C2D69AFB00DEDB7F57262D47C489316BCB2D20F69690FD19ABF65BE0F2AE0176FE3537CBB18AFC3ED0409CEBD4614C9F1AF77BFBCC23C4B335BB863FE8367FA590D2CD922F1E66134268AECF4311880F5B41EC90BB1AF061A4FB5145A196E7F995E1C7A4FAB84A9ABAA924AE133B826BC48C62648E5443B2A050A06EABF390857B042271BEBC86D9C211068CFCC3239D04F46FA7CC3FD90D2A9E1363F6551C1AB75197F43C734F131CEDFED4D8AB263C4040F0355A3AAB27587F36624876F12BB09842F46359586BAC4F19101112116CAFFFDE61E5B3F445E2AB355DB50FB47FF4B1B13E7B53E41C89D0C85B3AD36F3373D5079BB2F39BB6535F72E3B5E241F4F0B6EB260D152D6A3AD4406A06EC21C5A43BE0F3D1E130228D73B00C70D34C60E0C9DB6456394C8674802E677A0A6378F587D49D81F44FEA13F88C0F2EAE108D17E814AE867D124C8705751A6C52D51CF2A97037819A8284E74DBFC4586C6F51DDCF33320973764C77F247B5B0A43A1F56891CC5A259CC9900975530B71B77200CCB39D64EF64E064AA4F733FDC33F8BCC36E4C521377B64B6778F8930EFE7C64CC64B6F70F9F610ADC9DE9B0494691279DFBE34FE075F6F014D095511E514ADF31381FA36641771BE05BD42E2477034CE1D525C46CA8BD0608112AC17804279B74299562C1373619A2646699038B2FFFC9D9C8D14D5953010BA53EC7B"}
}
